package com.mipo.client.javase.company.flytek.beilun.cyservice;

import org.apache.http.HttpEntity;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

/**
 * CyService接口文档地址为：http://192.168.59.214:5000/
 *
 * @author jack lee
 **/
public class BeiLunCyserviceApiProduct {

	public static void main(String[] args) throws Exception {
		//盘服务
		//panDiridGet(); // 获取网盘文件夹目录，f6eea77f-306a-4cce-94f1-0d07857f2d9d
		//panFileList(); // 获取网盘文件夹目录下的文件列表（只有文件）。
		panDirsandfilesList();// 获取网盘根目录下的文件及文件夹列表（包含文件和文件夹）。

	}

	public static void panDiridGet() throws Exception {
		String url = "http://cyservice.blzy.bledu.net.cn/api?version=1.0&format=json&appkey=KtSNKxk3&"
				+ "method=pan.dirid.get&uid=4033020680000005945&folderType=yun_wendang&"
				+ "access_token=58ffe48c-6b19-4ea6-bb43-a96d1e3f4027&client_version=2.1.0.1001&product=std";
		excuteGetRequest(url);
	}

	public static void panFileList() throws Exception {
		String url = "http://cyservice.blzy.bledu.net.cn/api?version=1.0&format=json&appkey=KtSNKxk3&"
				+ "method=pan.file.list&uid=4033020680000005945&folderType=yun_wendang&page=1&limit=10&thumbwidth=202&thumbHeight=152&brief=true&dirId=f6eea77f-306a-4cce-94f1-0d07857f2d9d&extension=doc%2Cdocx%2Cxls%2Cxlsx%2Cppt%2Cpptx%2Cpps%2Cppsx%2Ctxt%2Crtf&"
				+ "access_token=58ffe48c-6b19-4ea6-bb43-a96d1e3f4027&client_version=2.1.0.1001&product=std";
		excuteGetRequest(url);
	}
	public static void panDirsandfilesList() throws Exception {
		String url = "http://cyservice.blzy.bledu.net.cn/api?version=1.0&format=json&appkey=KtSNKxk3&method=pan.dirsandfiles.list&uid=4033020680000005945&folderType=yun_wendang&page=1&limit=20&brief=true&extension=&dirId=0&access_token=3acd82aa-6131-4229-942e-ce190a04ea28&client_version=2.1.0.1001&product=std";
		excuteGetRequest(url);
	}
	
	

	public static void excuteGetRequest(String url) throws Exception {
		System.out.println("请求url："+url);
		CloseableHttpClient httpClient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet(url);
		CloseableHttpResponse response = httpClient.execute(httpGet); // 4.3版本不设置超时的话，一旦服务器没有响应，等待时间N久(>24小时)。
		HttpEntity entity = response.getEntity(); // 返回报文实体
		StatusLine status = response.getStatusLine();
		System.out.println("返回的状态码为：" + status); // 具体返回码(200)为status.getStatusCode();
		String ret = EntityUtils.toString(entity); // 将返回报文实体转换为字符串
		System.out.println("返回的报文为：" + ret);
		EntityUtils.consume(entity); // 释放是否可以去掉？
		response.close(); // 关闭资源,可以写在finally里
		httpGet.releaseConnection(); // 释放资源
		httpClient.close(); // 关闭资源
	}

}
